package com.universest.swordholder.tools

fun <T> List<T>.getItemSwapped(indexA: Int, indexB: Int): List<T> {
    if(indexA in this.indices && indexB in this.indices) {
        val list = this.toMutableList()
        list[indexA] = list[indexB].also { list[indexB] = list[indexA] }
        return list
    }
    return this
}

fun <T> MutableList<T>.replaceFirst(predicate:(item: T)->Boolean,newItem:T){
    val index = this.indexOfFirst(predicate)
    if(index in this.indices){
        this[index] = newItem
    }
}